//
// Created by gastonfeng on 2023/6/15.
//
#ifdef USE_TOUCH_2046
#include "touch_xpt2046.h"
#include <XPT2046_touch.h>

int touch_xpt2046::init()
{
    spi_touch = new SPIClass(hw_config->mosi, hw_config->miso, hw_config->clk);
    touch = new XPT2046_touch(hw_config->cs, *spi_touch);
    pinMode(hw_config->irq, INPUT);
    return touch->begin();
}

int touch_xpt2046::poll()
{
    uint16_t xy[2];
    if (digitalRead(hw_config->irq) == LOW)
    {
        touch->read_XY(xy);
        output->x = xy[0];
        output->y = xy[1];
        output->z = 1;
    }
    else
    {
        output->z = 0;
    }
    return output->z;
}
#endif
